from django.shortcuts import render
from .tests import send_apply_email
# Create your views here.
send_ci=0
def rpi_home(request):
    return render(request,'')
#探索主页
def in_home(request):
    return render(request,'app2_text/in_home.html')
#加入我们
def join_us(request):
    val=request.session.get('username', default=None)
    if val == None:
        return render(request, 'login.html', {"message": "请登录！"})
    if request.method == "POST":
        name_apply=str(request.POST.get("name_apply"))
        nianji_apply = str(request.POST.get("nianji_apply"))
        zhuanyei_apply = str(request.POST.get("zhuanyei_apply"))
        text_apply = str(request.POST.get("text_apply"))
        print(name_apply,nianji_apply,zhuanyei_apply,text_apply)
        if  len(name_apply)==0 or len(nianji_apply)==0 or len(zhuanyei_apply)==0 or len(text_apply)==0 or request.session["send_ci"]>=1:
            return render(request, 'app2_text/Join_us.html', {"message": "请正确填写报表或者重复填写"})
        print("发件人邮箱：",request.session["email"])
        if send_apply_email(name_apply,nianji_apply,zhuanyei_apply,text_apply,request.session["email"]):
            request.session["send_ci"]=1
            return render(request, 'app2_text/Join_us.html',{"message": "申请填报成功！"})
        else:
            return render(request, 'app2_text/Join_us.html',{"message": "申请填报失败！"})

    return render(request,'app2_text/Join_us.html')
